<?php

namespace app\backstage\controller;

use app\backstage\logic\PowerLogic;
use app\common\model\QuickUser;
use think\Controller;
use think\Db;
use think\facade\Env;

class Index extends Controller
{

    protected $middleware = [
        'VerifyJwt' => ['except' => ['test']],
        'VerifyPower' => ['except' => ['index','test']],
    ];


    public function test(){
        echo "test".PHP_EOL;
    }

    /**
     * 首页
     * @return mixed
     * @Author: whh
     */
    public function index()
    {
        $role = request()->_role;
        $user = request()->_user;

        $this->assign("_user", $user);//用户
        $this->assign("_role", $role);//角色
        switch ($role->alias) {
            case 'admin':
                $home_page = "data_center/index";
                break;
            case 'service':
                $home_page = "user/index";
                break;
            case 'finance':
                $home_page = "data_center/index";
                break;
            case 'agent':
                $home_page = "data_center/index";
                break;
            case 'channel':
                $home_page = "data_center/index";
                break;
            case 'eb':
                $home_page = "data_center/index";
                break;
            case 'operator':
                $home_page = "novel/index";
                break;
            case 'content':
                $home_page = "novel/index";
                break;
            case 'tc_operator':
                $home_page = "popup/popList";
                break;
            default:
                echo "角色未初始化配置，联系开发处理";
                die;
        }
        $powerLogic = new PowerLogic();
        $treeNodes = $powerLogic->treeMenu($role);
        $menuHtml = $powerLogic->menuFormat($treeNodes,0,'"'.$home_page.'"');
        $this->assign("menuHtml", $menuHtml);//菜单
        $home_page = "/" . $home_page;
        $this->assign("home_page", $home_page);//首页
        $cmsName = Env::get('cms.name','海外pwa');
        $this->assign("cmsName", $cmsName);//首页
        return $this->fetch();
    }
}
